﻿namespace HiMap.Carto
{
    using HiMap.Geometry;
    using System;
    using System.Collections.Generic;
    using System.Text;

    public class MemoryFeatureClassClass : FeatureClassClass
    {
        public MemoryFeatureClassClass(int InPtr, bool Used) : base(InPtr, Used)
        {
            base.m_InPtr = InPtr;
            base.m_Used = Used;
        }

        public MemoryFeatureClassClass(string Name, int MaxRecs, GeometryType GeoType, List<MemoryFeatureClassField> Fields) : base(0, false)
        {
            StringBuilder builder = new StringBuilder();
            int[] numArray = new int[Fields.get_Count()];
            int[] numArray2 = new int[Fields.get_Count()];
            StringBuilder builder2 = new StringBuilder();
            for (int i = 0; i < Fields.get_Count(); i++)
            {
                builder.Append("," + Fields.get_Item(i).FieldName);
                numArray[i] = this.GetVCFieldLength(Fields.get_Item(i));
                numArray2[i] = this.GetVCFieldFieldDecimals(Fields.get_Item(i));
                builder2.Append(this.GetVCFieldsType(Fields.get_Item(i)));
            }
            builder.Append(",");
            base.m_InPtr = HiMap.Carto.VC.KWG_MEMORYLAYER_CREATE(new StringBuilder(Name), new StringBuilder(Name), this.GetVCGeoType(GeoType), MaxRecs, builder, builder2, ref numArray[0], ref numArray2[0], Fields.get_Count());
            base.m_Used = false;
        }

        protected internal int GetVCFieldFieldDecimals(MemoryFeatureClassField fd)
        {
            switch (fd.FieldType)
            {
                case MemoryFeatureClassFieldType.Int:
                    return 0;

                case MemoryFeatureClassFieldType.String:
                    return 0;

                case MemoryFeatureClassFieldType.Float:
                    return fd.FieldDecimals;

                case MemoryFeatureClassFieldType.Double:
                    return fd.FieldDecimals;
            }
            return -1;
        }

        protected internal int GetVCFieldLength(MemoryFeatureClassField fd)
        {
            if (fd.FieldType == MemoryFeatureClassFieldType.Int)
            {
                return 4;
            }
            return fd.FieldLength;
        }

        protected internal string GetVCFieldName(MemoryFeatureClassField fd)
        {
            return fd.FieldName;
        }

        protected internal string GetVCFieldsType(MemoryFeatureClassField fd)
        {
            switch (fd.FieldType)
            {
                case MemoryFeatureClassFieldType.Int:
                    return "N";

                case MemoryFeatureClassFieldType.String:
                    return "C";

                case MemoryFeatureClassFieldType.Float:
                    return "F";

                case MemoryFeatureClassFieldType.Double:
                    return "D";
            }
            return "";
        }

        protected internal int GetVCGeoType(GeometryType geotype)
        {
            switch (geotype)
            {
                case GeometryType.Point:
                    return 1;

                case GeometryType.MultiPoint:
                    return 8;

                case GeometryType.Polyline:
                    return 3;

                case GeometryType.Polygon:
                    return 5;
            }
            return 0;
        }
    }
}

